/************************************************************************
 * <br>
 * <ul>
 * <li>版权所有：唐山弘川科技有限公司 2009－2020</li>
 * <li>创建日期：2009-8-10</li>
 * <li>初始作者：刘川</li>
 * </ul>
 * <ul>
 * <b>修订历史</b>
 * <li>1、</li>
 * </ul>
 ***********************************************************************/
package com.hy.enterprise.framework.persistence.domain.query.conditions ;

import com.hy.enterprise.framework.persistence.domain.query.internal.AliasFactory;

/**
 * <ul>
 * <li>设计作者：刘川</li>
 * <li>设计日期：2009-8-10</li>
 * <li>设计时间：下午03:15:56</li>
 * <li>设计目的：</li>
 * </ul>
 * <ul>
 * <b>修订历史</b>
 * <li>1、</li>
 * </ul>
 */
public class TernaryExpression < T , U , V > extends ConditionalExpression
{
	private final T	               lhs ;

	/**
	 * 三元操作符
	 */
	private final ITernaryOperator	operator ;

	private final U	               rhs1 ;
	private final V	               rhs2 ;

	/**
	 * 构造函数
	 * 
	 * @param lhs
	 * @param ternaryOperator
	 * @param rhs1
	 * @param rhs2
	 */
	public TernaryExpression (
	                           T lhs ,
	                           ITernaryOperator ternaryOperator ,
	                           U rhs1 ,
	                           V rhs2 )
	{
		this.lhs =
		           lhs ;
		this.operator =
		                ternaryOperator ;
		this.rhs1 =
		            rhs1 ;
		this.rhs2 =
		            rhs2 ;
	}

	@ Override
	public String getTargetRepresentation ( )
	{
		StringBuilder stringBuilder =
		                              new StringBuilder ( ) ;
		// lhs
		stringBuilder
		             .append ( AliasFactory
		                                   .safeStringForm ( this.lhs ) ) ;
		// op1
		stringBuilder
		             .append ( this.operator
		                                    .getStringRepresentation ( ) ) ;
		// rhs1
		stringBuilder
		             .append ( AliasFactory
		                                   .safeStringForm ( this.rhs1 ) ) ;
		// op2
		stringBuilder
		             .append ( this.operator
		                                    .getSecondStringRepresentation ( ) ) ;
		// rhs2
		stringBuilder
		             .append ( AliasFactory
		                                   .safeStringForm ( this.rhs2 ) ) ;
		return stringBuilder
		                    .toString ( ) ;
	}
}
